package com.itheima.algorithm.binarysearchtree;

import com.itheima.algorithm.binarytree.TreeNode;

/**
 * @author: TylerZhong
 * @description:
 */
public class E02Leetcode701 {

    class TreeNode {
        TreeNode left;
        int val;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }

        public TreeNode(TreeNode left, int val, TreeNode right) {
            this.left = left;
            this.val = val;
            this.right = right;
        }
    }

    public TreeNode insertIntoBST(TreeNode node, int val) {
        if (node == null) {
            return new TreeNode(val);
        }
        if (val < node.val) {
            node.left = insertIntoBST(node.left, val);
        }
        if (val > node.val) {
            node.right = insertIntoBST(node.right, val);
        }
        return node;
    }
}
